﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Controls;
using System.Drawing;
using Silvermoon.Shapes;
using Silvermoon.UI;

namespace Silvermoon.Windows.Styles
{
    public class MetroSliderStyle : StyleBase
    {

        public static readonly VisualStateManager MetroSliderManager = new VisualStateManager(
                new VisualStateGroup(
                    new VisualState(VState.Enabled),
                    new VisualState(VState.Disabled,
                        new ColorTransition
                        {
                            Property = Slider.ColorProperty,
                            Duration = 350,
                            To = PhoneColors.MediumDark
                        },
                        new ColorTransition
                        {
                            Property = Slider.ButtonColorProperty,
                            Duration = 350,
                            To = Color.DarkGray
                        },
                        new ColorTransition
                        {
                            Property = Slider.FillColorProperty,
                            Duration = 350,
                            To = Color.Gray
                        }
                        )
                ),
                new VisualStateGroup(
                    new VisualState(VState.ButtonReleased, 300),
                    new VisualState(VState.ButtonPressed,
                        new ScaleTransition
                        {
                            Property = Slider.ButtonScaleProperty,
                            To = new ScaleTransform(1.1f, 1.1f, 1f),
                            Duration = 10
                        }
                        )
                    )
                );



        public override void Apply(Control c)
        {
            Slider slider = (Slider)c;

            VisualStateManager.SetStateManagerIfEmpty(slider, MetroSliderManager);
            if (slider.Background == null) slider.Background = new RectangleShape { Size = Control.ScaledSize(16, 16) };
            if (slider.Fill == null) slider.Fill = new RectangleShape(PhoneColors.Accent) { Size = new Size(1, 16) };
            //if (slider.Button == null) slider.Button = Shape.Empty;
            if (slider.Button == null) slider.Button = new RectangleShape
              {
                  Size = Control.ScaledSize(Slider.DefaultButtonSize - 4, Slider.DefaultButtonSize - 4),
                  Color = PhoneColors.Light
              };
            if (slider.Color.IsEmpty) slider.Color = PhoneColors.MediumDark;
        }
    }
}
